// pages/order/index.js
import {login} from "../../utils/showmodel.js"
import {request} from "../../request/index"
Page({

  /**
   * 页面的初始数据
   */
  data: {
     token:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

 async handleGetUserInfo(e) {
    //获取用户信息
    const {encryptedData,iv,rawData,signature} = e.detail
    //获取用户的code登陆凭证
   const {code} = await  login()
   const loginParams = {encryptedData,iv,rawData,signature,code}
   //发起获取登陆token的请求
   const {data:res} = await request({
      url:'/users/wxlogin',
      data:loginParams,
      methods:'post'
    }) 
    //获取token 缓存起来 并跳转回上一个界面
   const {token} = this.data
   wx.setStorageSync('token', token);
   wx.navigateBack({
     delta: 1
   });
  }
})